
Partial Class Modules_Questionnaires_Controls_ansTime
    Inherits UserControl
    Implements DotNetPm.Business.Questionnaire.Taker.IAnswerUC


    Private _config, _answerType, _questionId, _sortId As String
    Private _timeType As String

    Public Property Answer() As String Implements DotNetPm.Business.Questionnaire.Taker.IAnswerUC.Answer
        Get
            If _timeType = "0" Then
                Return IIf(tpFrom.SelectedTime.Year < 10, String.Empty, tpFrom.SelectedTime)
            Else
                Return IIf(tpFrom.SelectedTime.Year < 10, String.Empty, tpFrom.SelectedTime) & "|" & _
                       IIf(tpTo.SelectedTime.Year < 10, String.Empty, tpTo.SelectedTime.Year)
            End If
        End Get
        Set(ByVal value As String)
            If String.IsNullOrEmpty(value) Then
                Exit Property
            End If
            If _timeType = "0" Then
                tpFrom.SelectedTime = value
            Else
                Dim val As String() = value.Split("|")
                tpFrom.SelectedTime = val(0)
                tpTo.SelectedTime = val(1)
            End If
        End Set
    End Property

    Public Property Config() As String Implements DotNetPm.Business.Questionnaire.Taker.IAnswerUC.Config
        Get
            Return _config
        End Get
        Set(ByVal value As String)
            If Not String.IsNullOrEmpty(value) Then
                _config = value
            End If
        End Set
    End Property

    Private Sub LoadAnswerControl()
        Dim val As String() = Split(Me.Config, "||")
        _sortId = val(0)
        _questionId = val(1)
        _answerType = val(2)
        Dim _isRequired As String = val(3)
        _timeType = val(4)
        Dim _timeInterval As Integer
        Integer.TryParse(val(5), _timeInterval)

        If _isRequired = "0" Then
            Dim reqFrom As New RequiredFieldValidator
            With reqFrom
                .ID = "reqVal"
                .ControlToValidate = "tpFrom"
                .Display = ValidatorDisplay.Dynamic
                .Text = "*"
                .ErrorMessage = "*<br/>The answer of Time type is required!"
                '.ErrorMessage = "Question# <b>" & _questionId & "</b> : The answer of type Time is required."
            End With
            phFrom.Controls.Add(reqFrom)
        End If

        tpFrom.MinuteInterval = _timeInterval
        tpTo.MinuteInterval = _timeInterval

        If _timeType = "0" Then
            tdFrom.InnerHtml = "Time :"
            lblTo.Visible = False
            tpTo.Visible = False
            phTo.Visible = False
        Else
            tdFrom.InnerHtml = "From :"
            If _isRequired = "0" Then
                Dim reqTo As New RequiredFieldValidator
                With reqTo
                    .ID = "reqTo"
                    .ControlToValidate = "tpTo"
                    .Display = ValidatorDisplay.Dynamic
                    .Text = "*"
                    .ErrorMessage = "The answer of Time type is required for To Time field!"
                    '.ErrorMessage = "Question# <b>" & _questionId & "</b> : The answer of type Time is required."
                End With
                phTo.Controls.Add(reqTo)
            End If
        End If
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        LoadAnswerControl()
    End Sub

    Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
        'LoadAnswerControl
    End Sub
End Class
